/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 *
 * @author ariel
 */
@Entity
@Table(name = "storage_cuts")
public class StorageCut implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;
    private Integer stock;
    private Integer stockLimit;
    private PantDesign pantDesign;
    private List<PantDetail> pantDetails;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name="id_storage_cut", unique=true, nullable=false)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "stock")
    public Integer getStock() {
        return stock;
    }

    public void setStock(Integer stock) {
        this.stock = stock;
    }

    @Column(name = "stock_limit")
    public Integer getStockLimit() {
        return stockLimit;
    }

    public void setStockLimit(Integer stockLimit) {
        this.stockLimit = stockLimit;
    }

    @JoinColumn(name = "id_pant_design", referencedColumnName = "id_pant_design")
    @ManyToOne(optional = false)
    public PantDesign getPantDesign() {
        return pantDesign;
    }

    public void setPantDesign(PantDesign pantDesign) {
        this.pantDesign = pantDesign;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "storageCut")
    public List<PantDetail> getPantDetails() {
        return pantDetails;
    }
    
    public void setPantDetails(List<PantDetail> pantDetails) {
        this.pantDetails = pantDetails;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof StorageCut)) {
            return false;
        }
        StorageCut other = (StorageCut) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE)
                .append(this.id).append(this.id).append(this.stock).append(this.stockLimit)
                .append(this.pantDesign)
                .toString();
    }

    @Transient
    public String getDatas(){
        return pantDesign.getDatas();
    }
}
